﻿//  -------------------- iSharePoint -------------------- //
// 
//  Company:	IT Complex, LLC
//  Project:	Smart.Common
//  File name:	CamlQueryBuilderGroupItem.cs
//  Developer:	Solomatov Igor
//  Created:	15.04.2012
// 
//  -------------------- iSharePoint -------------------- //

namespace Smart.Common.Entities
{
	/// <summary>
	/// QueryBuilder Query Order Item
	/// </summary>
	public class CamlQueryBuilderGroupItem<TExecutorType> : CamlQueryBuilderItem<TExecutorType>
		where TExecutorType : class
	{
		/// <summary>
		/// Field
		/// </summary>
		public string Field { get; set; }

		/// <summary>
		/// QueryBuilder Query Order Item
		/// </summary>
		/// <param name="field">Field name</param>
		public CamlQueryBuilderGroupItem(string field)
			: base("group")
		{
			Field = field;
		}

		/// <summary>
		/// Return Cache code
		/// </summary>
		public override int GetCacheCode()
		{
			return
				(Field == null ? 0 : Field.GetHashCode());
		}

		/// <summary>
		/// Format QueryBuilder statement
		/// </summary>
		public override string FormatQuery()
		{
			return
				string.Format("<FieldRef Name=\"{0}\" />", (Query == null ? Field : Query.Meta.FieldName(Field)));
		}
	}
}